/**
 * The file enables `@/store/index.js` to import all vuex modules
 * in a one-shot manner. There should not be any reason to edit this file.
 */

const files = require.context('.', true, /\.js$/)
let d = {}

function isObj (x) {
    var type = typeof x
    return x !== null && (type === 'object' || type === 'function')
}

var hasOwnProperty = Object.prototype.hasOwnProperty
var propIsEnumerable = Object.prototype.propertyIsEnumerable

function toObject (val) {
    if (val === null || val === undefined) {
        throw new TypeError('Cannot convert undefined or null to object')
    }

    return Object(val)
}

function assignKey (to, from, key) {
    var val = from[key]

    if (val === undefined || val === null) {
        return
    }

    if (hasOwnProperty.call(to, key)) {
        if (to[key] === undefined || to[key] === null) {
            throw new TypeError('Cannot convert undefined or null to object (' + key + ')')
        }
    }

    if (!hasOwnProperty.call(to, key) || !isObj(val)) {
        to[key] = val
    } else {
        to[key] = assign(Object(to[key]), from[key])
    }
}

function assign (to, from) {
    if (to === from) {
        return to
    }

    from = Object(from)

    for (var key in from) {
        if (hasOwnProperty.call(from, key)) {
            assignKey(to, from, key)
        }
    }

    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(from)

        for (var i = 0; i < symbols.length; i++) {
            if (propIsEnumerable.call(from, symbols[i])) {
                assignKey(to, from, symbols[i])
            }
        }
    }

    return to
}

function deepAssign (target) {
    target = toObject(target)

    for (var s = 1; s < arguments.length; s++) {
        assign(target, arguments[s])
    }

    return target
}

files.keys().forEach(key => {
    if (key === './index.js') return
    let keyPath = key.replace(/(\.\/|\.js)/g, '')
    keyPath = keyPath.split('/')
    let b = files(key).default
    if (!b.mutations) b.mutations = {}
    b.mutations._setStore = function (state, obj) {
        for (let key in obj) {
            if (state) state[key] = obj[key]
        }
    }
    for (let i = keyPath.length - 1; i >= 0; i--) {
        let a = {modules: {}, namespaced: true}
        a.modules[keyPath[i]] = b
        b = a
    }
    d = deepAssign(d, b)
})

export default d.modules
